package com.hx.springboot1.dao;

import com.hx.springboot1.pojo.dto.RoleNameDTO;
import com.hx.springboot1.pojo.entity.TabRole;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface RoleDao {
    @Select("select * from tab_role where role_id=#{id}")
    TabRole selectById(int id);
    @Select("select * from tab_role")
    List<TabRole> selectAllRoles();
    @Select("select * from tab_role where role_state = 0")
    List<TabRole> selectAllRolesEffect();
    @Select("select * from tab_role where role_name like #{name}")
    List<TabRole> selectAllRolesByName(String name);
    @Update("update tab_role set role_state = #{state} where role_id = #{roleId}")
    int updateRoleState(int state,int roleId);
    @Update("update tab_role set role_name = #{newName} where role_id = #{roleId}")
    int updateRoleName(String newName,int roleId);
    @Insert("insert into tab_role(role_name,role_state)" +
            " values(#{roleName},0)")
    int insertRole(String roleName);
    @Select("select GROUP_CONCAT(role_name) as role_name from tab_role a\n" +
            "join tab_user_role b on a.role_id = b.role_id\n" +
            "where b.user_id = #{userId}")
    RoleNameDTO selectRoleName(int userId);
}
